package com.ms.service.module.fish.message.server;

import java.nio.ByteBuffer;

import com.ms.service.module.fish.game.FishDesk;
import com.ms.service.module.fish.game.GameUser;
import com.ms.service.module.fish.game.KeepSeet;
import com.ms.service.module.fish.message.FishBaseMessage;

/**
 * 更新大厅机台信息
 * @author cuiwm
 */
public class UpdateRoomMessage extends FishBaseMessage {
	
	private FishDesk desk;
	private int index;
    

	public UpdateRoomMessage(FishDesk desk, int index) {
		this.desk = desk;
		this.index = index;
	}

	@Override
	public void writeBody(ByteBuffer buf) {
		buf.putInt(desk.getId());
		buf.put((byte) index);
		
		GameUser user = desk.getUser(index);
		KeepSeet seet = desk.keepSeat(index);
		if(user != null || seet != null) {
			if(user != null){
				writeString(buf, user.getId().toString());
				buf.put((byte) user.getUser().getSex());
				buf.putInt(0);
			}else{
				writeString(buf, seet.getUid().toString());
				buf.put((byte) 3);
				buf.putInt(seet.getLeftTime());
			}
		}else{
			writeString(buf, "");
			buf.put((byte) 0);
			buf.putInt(0);
		}
		
	}


}